package com.library.hibernatejpa.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
@NamedQueries(value={
@NamedQuery(name="publisher.nameLike", query="select r from Publisher r where r.name like ?"),
@NamedQuery(name="publisher.getPublisherBooks", query="select b from Book b WHERE b.publisher.id = ?")
}) 

//@NamedQuery(name="publisher.getPublisherBooks", query="select b from Publisher p, Book b JOIN b.publisher p WHERE p.id = ?")

public class Publisher implements Serializable
{
  private static final long serialVersionUID = 3805731902822385142L;
  private Integer id;
  private String name;
  private String address;
  //private List<Book> books;

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public Integer getId()
  {
    return id;
  }

  protected void setId(Integer id)
  {
    this.id = id;
  }


  public String getName()
  {
    return name;
  }

  public void setName(String name)
  {
    this.name = name;
  }

  public String getAddress()
  {
    return address;
  }

  public void setAddress(String address)
  {
    this.address = address;
  }

  //@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
  /*@OneToMany(cascade=CascadeType.ALL)
  public List<Book>getBooks()
  {
    return books;
  }
   
  
  public void setBooks(List<Book> books)
  {
    this.books = books;
  }*/
  
  public boolean equals(Object obj) 
  {
    return EqualsBuilder.reflectionEquals(this, obj);
  }

  public int hashCode()
  {
    return HashCodeBuilder.reflectionHashCode(this);
  }
  
  public String toString()
  {
    return ToStringBuilder.reflectionToString(this);
  }
}